home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / sdk / vfw11.win / vfwdk / debug.c1_ / debug.bin
Encoding:
Text File  |  1994-03-03  |  6.3 KB  |  296 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992, 1994  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. //  debug.c
  13. //
  14. //  Description:
  15. //      This file contains code yanked from several places to provide debug
  16. //      support that works in win 16 and win 32.
  17. //
  18. //
  19. //==========================================================================;
  20.  
  21. #ifdef DEBUG
  22.  
  23. #include <windows.h>
  24. #include <windowsx.h>
  25. #include <stdarg.h>
  26. #include "debug.h"
  27.  
  28.  
  29. //
  30. //  since we don't UNICODE our debugging messages, use the ASCII entry
  31. //  points regardless of how we are compiled.
  32. //
  33. #ifdef WIN32
  34.     #include <wchar.h>
  35. #else
  36.     #define lstrcatA            lstrcat
  37.     #define lstrlenA            lstrlen
  38.     #define GetProfileIntA      GetProfileInt
  39.     #define OutputDebugStringA  OutputDebugString
  40. #endif
  41.  
  42. //
  43. //
  44. //
  45. BOOL    __gfDbgEnabled          = TRUE;         // master enable
  46. UINT    __guDbgLevel            = 0;            // current debug level
  47.  
  48.  
  49. //--------------------------------------------------------------------------;
  50. //  
  51. //  void DbgVPrintF
  52. //  
  53. //  Description:
  54. //  
  55. //  
  56. //  Arguments:
  57. //      LPSTR szFormat:
  58. //  
  59. //      va_list va:
  60. //  
  61. //  Return (void):
  62. //      No value is returned.
  63. //  
  64. //--------------------------------------------------------------------------;
  65.  
  66. void FAR CDECL DbgVPrintF
  67. (
  68.     LPSTR                   szFormat,
  69.     va_list                 va
  70. )
  71. {
  72.     char                ach[DEBUG_MAX_LINE_LEN];
  73.     BOOL                fDebugBreak = FALSE;
  74.     BOOL                fPrefix     = TRUE;
  75.     BOOL                fCRLF       = TRUE;
  76.  
  77.     ach[0] = '\0';
  78.  
  79.     for (;;)
  80.     {
  81.         switch (*szFormat)
  82.         {
  83.             case '!':
  84.                 fDebugBreak = TRUE;
  85.                 szFormat++;
  86.                 continue;
  87.  
  88.             case '`':
  89.                 fPrefix = FALSE;
  90.                 szFormat++;
  91.                 continue;
  92.  
  93.             case '~':
  94.                 fCRLF = FALSE;
  95.                 szFormat++;
  96.                 continue;
  97.         }
  98.  
  99.         break;
  100.     }
  101.  
  102.     if (fDebugBreak)
  103.     {
  104.         ach[0] = '\007';
  105.         ach[1] = '\0';
  106.     }
  107.  
  108.     if (fPrefix)
  109.     {
  110.         lstrcatA(ach, DEBUG_MODULE_NAME ": ");
  111.     }
  112.  
  113. #ifdef WIN32
  114.     wvsprintfA(ach + lstrlenA(ach), szFormat, va);
  115. #else
  116.     wvsprintf(ach + lstrlenA(ach), szFormat, (LPSTR)va);
  117. #endif
  118.  
  119.     if (fCRLF)
  120.     {
  121.         lstrcatA(ach, "\r\n");
  122.     }
  123.  
  124.     OutputDebugStringA(ach);
  125.  
  126.     if (fDebugBreak)
  127.     {
  128.         DebugBreak();
  129.     }
  130. } // DbgVPrintF()
  131.  
  132.  
  133. //--------------------------------------------------------------------------;
  134. //  
  135. //  void dprintf
  136. //  
  137. //  Description:
  138. //      dprintf() is called by the DPF() macro if DEBUG is defined at compile
  139. //      time. It is recommended that you only use the DPF() macro to call
  140. //      this function--so you don't have to put #ifdef DEBUG around all
  141. //      of your code.
  142. //      
  143. //  Arguments:
  144. //      UINT uDbgLevel:
  145. //  
  146. //      LPSTR szFormat:
  147. //  
  148. //  Return (void):
  149. //      No value is returned.
  150. //
  151. //--------------------------------------------------------------------------;
  152.  
  153. void FAR CDECL dprintf
  154. (
  155.     UINT                    uDbgLevel,
  156.     LPSTR                   szFormat,
  157.     ...
  158. )
  159. {
  160.     va_list va;
  161.  
  162.     if (!__gfDbgEnabled || (__guDbgLevel < uDbgLevel))
  163.         return;
  164.  
  165.     va_start(va, szFormat);
  166.     DbgVPrintF(szFormat, va);
  167.     va_end(va);
  168. } // dprintf()
  169.  
  170.  
  171. //--------------------------------------------------------------------------;
  172. //  
  173. //  BOOL DbgEnable
  174. //  
  175. //  Description:
  176. //  
  177. //  
  178. //  Arguments:
  179. //      BOOL fEnable:
  180. //  
  181. //  Return (BOOL):
  182. //      Returns the previous debugging state.
  183. //  
  184. //--------------------------------------------------------------------------;
  185.  
  186. BOOL WINAPI DbgEnable
  187. (
  188.     BOOL                    fEnable
  189. )
  190. {
  191.     BOOL                fOldState;
  192.  
  193.     fOldState      = __gfDbgEnabled;
  194.     __gfDbgEnabled = fEnable;
  195.  
  196.     return (fOldState);
  197. } // DbgEnable()
  198.  
  199.  
  200. //--------------------------------------------------------------------------;
  201. //  
  202. //  UINT DbgSetLevel
  203. //  
  204. //  Description:
  205. //  
  206. //  
  207. //  Arguments:
  208. //      UINT uLevel:
  209. //  
  210. //  Return (UINT):
  211. //      Returns the previous debugging level.
  212. //  
  213. //--------------------------------------------------------------------------;
  214.  
  215. UINT WINAPI DbgSetLevel
  216. (
  217.     UINT                    uLevel
  218. )
  219. {
  220.     UINT                uOldLevel;
  221.  
  222.     uOldLevel    = __guDbgLevel;
  223.     __guDbgLevel = uLevel;
  224.  
  225.     return (uOldLevel);
  226. } // DbgSetLevel()
  227.  
  228.  
  229. //--------------------------------------------------------------------------;
  230. //  
  231. //  UINT DbgGetLevel
  232. //  
  233. //  Description:
  234. //  
  235. //  
  236. //  Arguments:
  237. //      None.
  238. //  
  239. //  Return (UINT):
  240. //      Returns the current debugging level.
  241. //  
  242. //--------------------------------------------------------------------------;
  243.  
  244. UINT WINAPI DbgGetLevel
  245. (
  246.     void
  247. )
  248. {
  249.     return (__guDbgLevel);
  250. } // DbgGetLevel()
  251.  
  252.  
  253. //--------------------------------------------------------------------------;
  254. //  
  255. //  UINT DbgInitialize
  256. //  
  257. //  Description:
  258. //  
  259. //  
  260. //  Arguments:
  261. //      BOOL fEnable:
  262. //  
  263. //  Return (UINT):
  264. //      Returns the debugging level that was set.
  265. //  
  266. //--------------------------------------------------------------------------;
  267.  
  268. UINT WINAPI DbgInitialize
  269. (
  270.     BOOL                    fEnable
  271. )
  272. {
  273.     UINT                uLevel;
  274.  
  275.     uLevel = GetProfileIntA(DEBUG_SECTION, DEBUG_MODULE_NAME, (UINT)-1);
  276.     if ((UINT)-1 == uLevel)
  277.     {
  278.         //
  279.         //  if the debug key is not present, then force debug output to
  280.         //  be disabled. this way running a debug version of a component
  281.         //  on a non-debugging machine will not generate output unless
  282.         //  the debug key exists.
  283.         //
  284.         uLevel  = 0;
  285.         fEnable = FALSE;
  286.     }
  287.  
  288.     DbgSetLevel(uLevel);
  289.     DbgEnable(fEnable);
  290.  
  291.     return (__guDbgLevel);
  292. } // DbgInitialize()
  293.  
  294. #endif // #ifdef DEBUG
  295.  
  296.